<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>消息</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link href="/css/css_likeHistory.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            var userId = JSON.parse(sessionStorage.getItem("user")).id;

            /** 将时间戳转成时间格式的函数 ckw**/
            function getMyDate(str){
                var oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth()+1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间
                return oTime;
            };
            /** 日期补0 ckw**/
            function getzf(num){
                if(parseInt(num) < 10){
                    num = '0'+num;
                }
                return num;
            }

            var loaded = false; //是否加载完毕,默认没有
            var likerNum = 0;
            var currentPage = 1;//当前页
            var pages;//总页数
            var travelData=[];//定义一个数组用来接收每次分页时的数据
            function query() {//记得传递当前页这个参数
                $.get("/travelLike/getTravelLiker?userId="+userId+"&currentPage="+currentPage,function (data) {
                    likerNum = data.list.length;
                    console.log(likerNum);
                    $.merge(travelData,data.list);
                    var json = {
                        list: travelData
                    };
                    $(".userGood").renderValues(json,{
                        getHref:function (item,value) {
                            var url = $(item).data("href");
                            $(item).attr("href",url+value);
                        },
                        getTravelHref:function (item,value) {
                            var url = $(item).data("href");
                            $(item).attr("href",url+value);
                        },
                        getTime:function (item,value) {
                            var data = getMyDate(value);
                            $(item).html(data);
                        }
                    });
                    pages = data.pages;
                    /** 发请求改变查看状态 ckw**/
                    $.post("/travelLike/changBrower",{userId:userId},function (data) {
                        if (data.success){
                            if(likerNum>0){
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '亲亲,有'+likerNum+'人为你点赞哦,你好棒棒哦!',
                                    autoClose: 2000,
                                    position: 'center'  // center: 居中; bottom: 底部
                                });
                            }else{
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '亲亲,还没有人赞过你哦!',
                                    autoClose: 2000,
                                    position: 'center'  // center: 居中; bottom: 底部
                                });
                            }
                        }
                    })
                });
                currentPage ++;
            }

            //默认查询第一页
            query();


            //监听滚动事件,当滚动条发生变化时触发
            $(window).scroll(function(){
                //document滚上去的高度+手机窗口的高度 >= 整个文档的高度
                if (($(document).scrollTop()+$(window).height()) >= $(document).height()-1){
                    if (currentPage <= pages){//如果当前页数小于等于总页数
                        query();
                    }else {
                        $(document).dialog({
                            type : 'notice',
                            content: '<span class="info-text">我是有底线的!</span>',
                            autoClose: 1000,
                            position: 'bottom'
                        });
                    }
                }
            });
        });


    </script>

</head>
<body>

<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed b-line" >
        <a href="/mine/message.html" class="aui-navBar-item">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">赞我的</span>
        </div>
        <a href="javascript:;" class="aui-navBar-item">
        </a>
    </header>

    <section class="aui-scrollView userGood">
        <div class="aui-list-box" render-loop="list">

            <div class="aui-flex">
                <br>
                <a data-href="/userProfiles.html?id=" render-key="list.likerId" render-fun="getHref">
                    <div class="aui-flex-logo">
                        <img render-src="list.likerHeadImgUrl" alt="">
                    </div>
                </a>
                <div class="aui-flex-box">
                    <h2>
                        <span render-html="list.likerNickName"></span>
                        <span style="font-size: 12px">赞了你的游记</span>
                        <span style="font-size: 10px" render-key="list.createTime" render-fun="getTime"></span>
                    </h2>
                    <br>
                    <a data-href="/travelContent.html?id=" render-key="list.travelId" render-fun="getTravelHref">
                        <h3 style="color: #ff5061;font-size: 14px"  render-html="list.travelTitle"></h3>
                    </a>

                </div>
            </div>

        </div>
    </section>

</section>

</body>
</html>